class Solution(object):
    def imageSmoother(self, M):
        """
        :type M: List[List[int]]
        :rtype: List[List[int]]
        """
        res = []
        r ,l = len(M),len(M[0])
        for i in range(r):
            res.append([])
            for j in range(l):
                count = 0
                value = M[i][j]
                count+=1
                if i - 1 >= 0:
                    value += M[i - 1][j]
                    count += 1
                    if j-1>=0:
                        value += M[i-1][j - 1]
                        count += 1
                    if j + 1 < l :
                        value += M[i - 1][j + 1]
                        count += 1
                if i+1<r:
                    value+=M[i+1][j]
                    count+=1
                    if j-1>=0:
                        value += M[i+1][j - 1]
                        count += 1
                    if j + 1 < l :
                        value += M[i + 1][j + 1]
                        count += 1
                if j-1>=0:

                    value += M[i][j-1]
                    count += 1

                if j+1 < l:

                    value += M[i][j+1]
                    count += 1


                res[i].append(value/count)
        return res

a = [[1,1,1],[1,0,1],[1,1,1]]
s= Solution()
m  =s.imageSmoother(a)
print(m)



